package design.singleton;

public class Person {
    private String name;
    private String age;

    //private static Person instance = new Person();
    private static Person instance;

    private Person() {
        System.out.println("创建Person");
    }

    public static synchronized Person getTom() {
        //如果没有实例，才创建
        if (instance == null) {
            synchronized (Person.class) {
                if (instance == null) {
                    Person person = new Person();
                    instance = person;
                }
            }
        }
        return instance;
    }
}
